package org.example.refectx;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestX {

    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        XController xController = new XController();
        Class<? extends XController> aClass = xController.getClass();

        XService xService = new XService();
        Field xServic1Filed = aClass.getDeclaredField("xservice");
        xServic1Filed.setAccessible(true);

        String name = xServic1Filed.getName();
        String toSetName = name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
        String setName = "set" + toSetName;

        Method method = aClass.getMethod(setName, XService.class);
        Object invoke = method.invoke(xController, xService);

        System.out.println(xController.getXservice());

        System.out.println("xService is equal : " + (xService == xController.getXservice()));
    }
}
